package com.coin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coin.domain.AdminAddress;
import com.coin.mapper.AdminAddressMapper;
import com.coin.service.AdminAddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Auther: 李 力
 * @Date: 2025/6/12
 * @Description: com.coin.service.impl
 * @version: 1.0
 */
@Service
public class AdminAddressServiceImpl extends ServiceImpl<AdminAddressMapper, AdminAddress> implements AdminAddressService {

    /**
     * @Description: 查询归集地址
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @Override
    public Page<AdminAddress> findByPage(Page<AdminAddress> page, Long coinId) {
        LambdaQueryWrapper<AdminAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = queryWrapper.eq(coinId != null, AdminAddress::getCoinId, coinId);
        return page(page, queryWrapper);
    }

    /**
     * @Description: 归集地址的新增
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveAdminAddress(AdminAddress adminAddress) {
        if (adminAddress == null) {
            throw new RuntimeException("参数为空");
        }
        return save(adminAddress);
    }

    /**
     * @Description: 归集地址的修改
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateAdminAddress(AdminAddress adminAddress) {
        if (adminAddress == null) {
            throw new RuntimeException("参数为空");
        }
        return updateById(adminAddress);
    }
}
